package net.jiastudy.biz.user.service;

import java.util.List;
import java.util.Map;
import java.util.Set;

import net.jiastudy.biz.datasync.LeaderImporter;
import net.jiastudy.biz.datasync.UserImporter;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.cache.annotation.Caching;
import org.springframework.data.domain.Sort;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;

import com.baomidou.mybatisplus.plugins.Page;

import net.jiastudy.biz.user.entity.User;
import net.jiastudy.core.common.CacheExpire;

public interface UserService extends UserDetailsService {

	@Cacheable(value = "user:id", key = "#id", unless = "#result == null")
	@CacheExpire(expire = 90)
	public User getUserById(Long id);

	public User getUserByName(String name);

	public void batchSetLeader(List<LeaderImporter> list);

	public User createUser(User user);

	@Caching(evict = { @CacheEvict(value = "user:username", key = "#user.username"),
			@CacheEvict(value = "user:id", key = "#user.id") })
	public User updateUser(User user);

	public boolean checkUsernameExists(String username, Long currentUserId);

	UserDetails loadUserByUsername(String username) throws UsernameNotFoundException;

	@Cacheable(value = "user:username", key = "#username", unless = "#result == null")
	@CacheExpire(expire = 360)
	public User getUserByUsername(String username);

	public Set<String> findPermissionCodesByUserId(Long userId);

	public boolean changePassword(Long userId, String oldPassword, String newPassword);

	public boolean changePassword(Long userId, String newPassword);

	public List<User> findUsersByIds(Set<Long> ids);

	public Page<User> pageUsers(Page<User> page, Map<String, String> conditions, Sort sort);

	public boolean disableUser(Long id);

	public boolean enableUser(Long id);

	public void importUsers(List<UserImporter> list);
}
